// compute the common and correlation matrix of the solvers
// correlation(i,j) is defined as common(i,j)/max(i,j) 

#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
using namespace std;

short NUM_OF_SOLVERS; 
short NUM_OF_PROBLEMS;
double TIME_LIMIT;

vector<string> split(string& str, char sep ) {
	vector< string > ret;
	string::iterator from( str.begin() );
    int i = 0;
    while( true ) {
		string::iterator to = find( from, str.end(), sep );
        if( to == str.end() ) {
            string temp(from,to);
			ret.push_back( temp );
            break;
        } else {
			string temp(from,to);
            ret.push_back( temp );
            from = ++to;
        }
        i++;
    }
	return ret;
}

int main(){
    
    vector<int> solver;
    int cnt;
    double time;
    
    bool table[30][3000];
    int solveNum[30];
    double correlation[30][30];
    int common;
    int commonM[30][30];

    vector<string> solverNames;
    
    freopen("ga.in","r",stdin);freopen("correlation.out","w",stdout);
    string solverName = "auto|blast|simp|fast|best|force|fastsimp|meson|metis";
    solverNames = split(solverName, '|');

    memset(table,false,sizeof(table));

    // Reading The Constants
    cin >> NUM_OF_SOLVERS; 
    cin >> NUM_OF_PROBLEMS;
    cin >> TIME_LIMIT;

    // Reading The Table
    for (int i = 0; i < NUM_OF_SOLVERS; i ++ ){
        cnt = 0;        
        for (int j = 0; j < NUM_OF_PROBLEMS; j ++ ){
            cin >> time;
            if ( time <= TIME_LIMIT) {
                cnt++;
                table[i][j] = true;            
            }
        }
        solveNum[i] = cnt;
        cout << solverNames[i] << ": " << cnt << endl;
    }
    
    for (int i = 0; i < NUM_OF_SOLVERS; i ++ ){
        for (int j = i; j < NUM_OF_SOLVERS; j ++ ){
            common = 0;
            for (int k = 0; k < NUM_OF_PROBLEMS; k ++ ){
                if (table[i][k] && table[j][k]){
                    common ++;             
                }
            }
            commonM[i][j] = common;
            correlation[i][j] = (double)common / (double)max(solveNum[i],solveNum[j]);
        }
    }


    cout << "Common Matrix:" << endl;
    for (int i = 0; i < NUM_OF_SOLVERS; i ++ ){
        for (int j = 0; j < NUM_OF_SOLVERS; j ++ ){
            if ( i <= j )
                cout << setw(5) << commonM[i][j] << " ";
            else
                cout << setw(5) << commonM[j][i] << " ";               
        }
        cout << endl;
    }    


    cout << "Correlation Matrix:" << endl;
    for (int i = 0; i < NUM_OF_SOLVERS; i ++ ){
        for (int j = 0; j < NUM_OF_SOLVERS; j ++ ){
            if ( i <= j )
                cout << setw(10) << correlation[i][j] << " ";
            else
                cout << setw(10) << correlation[j][i] << " ";               
        }
        cout << endl;
    }    
      
}
